import {message, Modal} from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import {upperShelf} from "@/services/ant-design-pro/marketing";
import {useRef} from "react";
import {ActionType} from "@ant-design/pro-table";


const { confirm } = Modal;


const OffShelf = (props) => {
  const {record} = props
  const actionRef = useRef<ActionType>()

  function showPromiseConfirm() {
    confirm({
      title: `您确定要下架【${record.title}】商品吗？`,
      icon: <ExclamationCircleOutlined />,
      content: '下架将会删除前台用户已砍的所有记录，所有用户将重新发起砍价,您确定要这样操作吗？',
      onOk() {
        upperShelf(record.id,{
          status: record.status ? 1 : 0,
        }).then(()=>{
          message.success('操作成功！')
          actionRef.current?.reload()
        })
        console.log(record.status)
      },
      onCancel() {
        actionRef.current?.reload()
        return

        console.log(record.status)
      },
      cancelText: '取消下架操作',
      okText: '我想好了，确定要下架'
    });
  }

  return (
    <div>
      <span onClick={showPromiseConfirm}>上架</span>
    </div>
  );
};

export default OffShelf;
